<template>
	<view>
		<view class="">
			测试页面
		</view>
		<view class="">
			<text>{{r1}}</text>
		</view>
		<view class="">
			<text>{{r2}}--{{ tools.formatDate((r2.lastupdate)) }}</text>
		</view>
		<view class="">
			<text>{{r3}}</text>
		</view>
		<view>
			<uni-card>
				<button type="default" @click="login">登录</button>
				<button type="default" @click="logout">登出</button>
			</uni-card>

		</view>
		<view>
			<uni-card>
				<text>
					是否登录：
					{{islogin}}
				</text>
			</uni-card>

		</view>
		<view>
			<uni-card>
				<text>
					用户信息
					{{userinfo}}
				</text>
			</uni-card>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		api
	} from '../../script/api.js'
	import {
		tools
	} from '../../script/tools.js'
	const r1 = ref('')
	const r2 = ref('')
	const r3 = tools.concatJson({
		name: "张三"
	}, {
		id: 100,
		age: 18
	})

	api.get('/tools/pinyin', {
		info: "黑暗骑士"
	}, (data) => {
		r1.value = JSON.stringify(data)
	})

	api.post('/test/converter/json', {
		"lid": 1,
		"logType": "用户登录",
		"logInfo": "用户登录成功",
		"lastupdate": "2024-02-03"
	}, (data) => {
		if (data.success) {
			r2.value = data.data
		}
	})

	// 用户登录测试

	import {
		userinfoStore
	} from '../../store/index.js'

	import {
		storeToRefs
	} from 'pinia'

	const {
		updateUserInfo
	} = userinfoStore()

	const {
		islogin,
		userinfo
	} = storeToRefs(userinfoStore())

	const login = () => {
		api.post('/auth', {
			username: 'test',
			password: 'test_pwd'
		}, (data) => {
			console.log("登录信息", data);
			updateUserInfo(data.success, data.data)
		})
	}
	const logout = () => {
		updateUserInfo(false, {})
		api.delete('/auth', {}, () => {})
	}
</script>

<style lang="scss">

</style>